package cn.zmit.kuxi.holder;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.xdroid.common.utils.ToastUtils;
import com.xdroid.functions.holder.ViewHolderBase;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import cn.zmit.kuxi.R;
import cn.zmit.kuxi.activity.WillAnnounceActivity;
import cn.zmit.kuxi.contants.Url;
import cn.zmit.kuxi.entity.NewRecordEntity;
import cn.zmit.kuxi.image.ImageDisplayer;

/** * @author chenxu @parameter * @return */
public class MainNewRecordHolder extends ViewHolderBase<NewRecordEntity> {
	private Context context;
	private ImageView image_getGoods;
	private TextView tv_goodsUser;
	private RelativeLayout mRelativeLayout;

	@SuppressLint("InflateParams")
	@Override
	public View createView(LayoutInflater layoutInflater) {
		context = layoutInflater.getContext();
		View view = layoutInflater.inflate(R.layout.item_main_new_battlefield,
				null);
		image_getGoods = (ImageView) view.findViewById(R.id.image_get_goods);
		tv_goodsUser = (TextView) view.findViewById(R.id.tv_get_goods_user);
		mRelativeLayout = (RelativeLayout) view
				.findViewById(R.id.rl_item_mainNew);
		return view;
	}

	@Override
	public void showData(int position, final NewRecordEntity itemData) {
		if (itemData.getUrl() != null && itemData.getUrl().length() > 0) {
			ImageDisplayer.getInstance().dispalyImageWithRadius(
					Url.IMAGE_PICTURES + itemData.getUrl(), image_getGoods, 0);
		} else {
			image_getGoods.setImageResource(R.drawable.user_pic_def);
		}
		String phone = itemData.getPhone();
		if (itemData.getOldtime() - itemData.getNowtime() > 0) {
			tv_goodsUser.setText("敬请期待");
		} else {
			if (phone.length() == 11) {
				String newPhone = phone;
				tv_goodsUser.setText("恭喜" + newPhone + "获得"
						+ itemData.getGoods_name());
			}
		}

		mRelativeLayout.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				Bundle bundle = new Bundle();
				bundle.putString("flag", "首页");
				bundle.putString("gp_id", itemData.getGp_id());
				bundle.putString("title", itemData.getTitle());
				bundle.putString("goodsName", itemData.getGoods_name());
				intent.putExtras(bundle);
				intent.setClass(context, WillAnnounceActivity.class);
				context.startActivity(intent);
			}
		});
	}

}
